/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view;

import componenten.Database;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import model.Deelnemers;
import model.Leden;
import model.Masterclass;

/**
 *
 * @author daveronvanderham
 */
public class MasterclassBeheren extends javax.swing.JFrame {

    private Masterclass clsMasterclass;

    /**
     * Creates new form MasterclassBeheren
     */
    public MasterclassBeheren(String masterclass_id) {
        initComponents();

        this.clsMasterclass = new Masterclass(masterclass_id);
        masterclass.setText(Integer.toString(clsMasterclass.getMasterclass_id()));
        Master.setText(clsMasterclass.getMasterBijnaam(clsMasterclass.getMaster()));
        Datum.setText(clsMasterclass.getDatum());
        Tijd.setText(clsMasterclass.getTijd());
        Deelnemers.setText(Integer.toString(clsMasterclass.getMin_deelnemers()));
        postcode.setText(clsMasterclass.getLocatie_postcode());
        huisnr.setText(clsMasterclass.getLocatie_huisnummer());
        Mstatus.setText(clsMasterclass.getStatus());
        vulTabelDeelnemer(clsMasterclass.getMasterclass_id());
        vulTabelLeden();
    }

    private MasterclassBeheren() {
        throw new UnsupportedOperationException("Not yet implemented");
    }

    private void vulTabelDeelnemer(int masterclass_id) {
        //Ophalen van de toernooien uit de database

        Deelnemers deelnemer = new Deelnemers();
        String[] kolommen = {"lid", "email", "betaald?"};
        DefaultTableModel model = new DefaultTableModel(kolommen, 0);

        int aantalLocaties = deelnemer.haalAantalLocatiepOp(masterclass_id);

        //Lijstje aanmaken voor de tennistoernooien die we uit de database gaan halen. 
        Deelnemers[] deelnemers;
        if (aantalLocaties == -1) {
            //return null;
        } else {
            deelnemers = new Deelnemers[aantalLocaties];
        }

        try {

            String sql = "SELECT d.lid_id , p.persoon_email , d.deelnemer_betaalstatus FROM deelnemer d join persoon p on d.lid_id = p.persoon_id WHERE masterclass_id = " + masterclass_id + "";
            ResultSet resultaat = Database.executeSelectQuery(sql);

            int teller = 0;
            while (resultaat.next()) {

                int dlnmr = resultaat.getInt("d.lid_id");
                String email = resultaat.getString("p.persoon_email");
                String btlng = resultaat.getString("d.deelnemer_betaalstatus");

                Deelnemers tabelVulling = new Deelnemers(dlnmr, clsMasterclass.getMasterclass_id(), email, btlng);
                model.addRow(tabelVulling.getInformatie());
            }

        } catch (SQLException e) {
        }

        tblDeelnemer.setModel(model);

    }

    private void vulTabelLeden() {
       Leden lid = new Leden();
        String[] kolommen = {"id", "email", "rating"};
        DefaultTableModel model = new DefaultTableModel(kolommen, 0);
        
        int aantalLocaties = lid.haalAantalLedenOp();

        //Lijstje aanmaken voor de tennistoernooien die we uit de database gaan halen. 
        Leden[] leden;
        if (aantalLocaties == -1) {
            //return null;
        } else {
            leden = new Leden[aantalLocaties];
        }
        
        try {
            
            String sql = "select l.persoon_id , l.lid_rating,p.persoon_email from lid l join persoon p on l.persoon_id = p.persoon_id where l.persoon_id not in (SELECT lid_id FROM deelnemer WHERE masterclass_id = " + clsMasterclass.getMasterclass_id() + ")AND l.lid_rating >= "+clsMasterclass.getMin_rating()+"";
            ResultSet resultaat = Database.executeSelectQuery(sql);
            
            int teller = 0;
            while (resultaat.next()) {
                
                int lid_id = resultaat.getInt("persoon_id");
                String email = resultaat.getString("persoon_email");
                int rating = resultaat.getInt("lid_rating");
                
                Leden tabelVulling = new Leden(lid_id, email, rating);
                model.addRow(tabelVulling.getInformatie());
            }
            
            
        } catch (SQLException e) {
        }
        tblLeden.setModel(model);
    }

    private int getMaxdeelnemers(String postcode, String huisnummer) {
        // haalt het maximale aantal deelnemers van de locatie van de masterclass op.
        int locatieMaxDeelnemers = 0;
        try {
            String sql = "SELECT locatie_max_deelnemers FROM locatie WHERE locatie_postcode = '" + postcode + "' AND locatie_huisnummer = '" + huisnummer + "';";



            ResultSet resultaat = Database.executeSelectQuery(sql);

            int teller = 0;
            while (resultaat.next()) {

                locatieMaxDeelnemers = resultaat.getInt("locatie_max_deelnemers");

            }

        } catch (SQLException e) {
        }
        return locatieMaxDeelnemers;

    }

    private int getdeelnemers(int masterclass) {
        //count alle deelnemers van de masterclass
        int MaxDeelnemers = 0;

        try {
            String sql = "SELECT COUNT(*) as max FROM deelnemer WHERE masterclass_id = " + masterclass + ";";



            ResultSet resultaat = Database.executeSelectQuery(sql);


            while (resultaat.next()) {

                MaxDeelnemers = resultaat.getInt("max");

            }

        } catch (SQLException e) {
        }
        return MaxDeelnemers;
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        tblDeelnemer = new javax.swing.JTable();
        Master = new javax.swing.JTextField();
        Datum = new javax.swing.JTextField();
        Tijd = new javax.swing.JTextField();
        Deelnemers = new javax.swing.JTextField();
        deelnemerToevoegen = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        masterclass = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        cancel = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        tblLeden = new javax.swing.JTable();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        postcode = new javax.swing.JTextField();
        huisnr = new javax.swing.JTextField();
        jButton2 = new javax.swing.JButton();
        btnVernieuwen = new javax.swing.JButton();
        jLabel5 = new javax.swing.JLabel();
        Mstatus = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setMinimumSize(null);

        tblDeelnemer.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        tblDeelnemer.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tblDeelnemerMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(tblDeelnemer);

        Master.setEditable(false);
        Master.setEnabled(false);

        Datum.setEditable(false);
        Datum.setEnabled(false);
        Datum.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                DatumActionPerformed(evt);
            }
        });

        Tijd.setEditable(false);
        Tijd.setEnabled(false);

        Deelnemers.setEditable(false);
        Deelnemers.setEnabled(false);

        deelnemerToevoegen.setText("<");
        deelnemerToevoegen.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deelnemerToevoegenActionPerformed(evt);
            }
        });

        jButton3.setText("opzeggen");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jLabel1.setText("master");

        jLabel2.setText("datum");

        jLabel3.setText("tijd");

        jLabel4.setText("min deelnemers");

        masterclass.setEditable(false);
        masterclass.setEnabled(false);

        jLabel6.setText("masterclass id");

        cancel.setText("cancel");
        cancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelActionPerformed(evt);
            }
        });

        tblLeden.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane2.setViewportView(tblLeden);

        jLabel8.setText("deelnemers");

        jLabel9.setText("leden");

        jButton1.setText("voltooien");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jLabel10.setText("postcode");

        jLabel11.setText("huisnr");

        postcode.setEditable(false);
        postcode.setEnabled(false);

        huisnr.setEditable(false);
        huisnr.setEnabled(false);

        jButton2.setText("deelnemer wijzigen");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        btnVernieuwen.setText("vernieuwen");
        btnVernieuwen.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnVernieuwenActionPerformed(evt);
            }
        });

        jLabel5.setText("status");

        Mstatus.setEditable(false);
        Mstatus.setEnabled(false);

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
                    .add(layout.createSequentialGroup()
                        .add(jButton1)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jButton3)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(cancel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 69, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .add(jButton2))
                    .add(layout.createSequentialGroup()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                                .add(0, 0, Short.MAX_VALUE)
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                                    .add(layout.createSequentialGroup()
                                        .add(jLabel6)
                                        .add(24, 24, 24))
                                    .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
                                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                                            .add(org.jdesktop.layout.GroupLayout.LEADING, jLabel1)
                                            .add(org.jdesktop.layout.GroupLayout.LEADING, jLabel2)
                                            .add(org.jdesktop.layout.GroupLayout.LEADING, jLabel3)
                                            .add(org.jdesktop.layout.GroupLayout.LEADING, jLabel4))
                                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)))
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(masterclass, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 99, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                    .add(Master, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 99, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                    .add(Datum, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 99, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                    .add(Tijd, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 99, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                    .add(Deelnemers, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 99, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                                .add(jLabel10)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .add(postcode, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 99, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(jLabel11)
                                    .add(jLabel5))
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                                    .add(Mstatus)
                                    .add(huisnr, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 99, Short.MAX_VALUE))))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jLabel8)
                            .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 330, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(deelnemerToevoegen, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 39, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jLabel9)
                            .add(jScrollPane2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 330, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, btnVernieuwen))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(15, 15, 15)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                            .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 275, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(layout.createSequentialGroup()
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                                    .add(masterclass, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                    .add(jLabel6))
                                .add(6, 6, 6)
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                                    .add(Master, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                    .add(jLabel1))
                                .add(6, 6, 6)
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                                    .add(Datum, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                    .add(jLabel2))
                                .add(6, 6, 6)
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                                    .add(Tijd, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                    .add(jLabel3))
                                .add(6, 6, 6)
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                                    .add(Deelnemers, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                    .add(jLabel4))
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                                    .add(postcode, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                    .add(jLabel10))
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                                    .add(huisnr, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                    .add(jLabel11))
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                                    .add(Mstatus, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                    .add(jLabel5)))
                            .add(jScrollPane2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 275, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                    .add(layout.createSequentialGroup()
                        .add(75, 75, 75)
                        .add(deelnemerToevoegen)))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jLabel9)
                    .add(jLabel8))
                .add(4, 4, 4)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jButton1)
                    .add(jButton3)
                    .add(cancel)
                    .add(jButton2)
                    .add(btnVernieuwen))
                .add(14, 14, 14))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void DatumActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_DatumActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_DatumActionPerformed

    private void deelnemerToevoegenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deelnemerToevoegenActionPerformed
//voegt deelnemers toe en kijkt of het aantal deelnemers niet het maximum heeft bereikt.        
        int geselecteerdeRij = tblLeden.getSelectedRow();
        if (geselecteerdeRij == -1) {
            JOptionPane.showMessageDialog(null, "Selecteer eerst een lid voordat u kunt toevoegen");
        } else {
        int max = getMaxdeelnemers(postcode.getText(), huisnr.getText());
        int aantal = getdeelnemers(clsMasterclass.getMasterclass_id());
        System.out.println(max);
        System.out.println(aantal);
        if (aantal >= max) {
            JOptionPane.showMessageDialog(null, "het maximum aantal deelnemers is al bereikt");
        } else {


            int row = tblLeden.getSelectedRow();
            String lid = (String) tblLeden.getModel().getValueAt(row, 0);
            Deelnemers nieuwDeelnemer = new Deelnemers(clsMasterclass.getMasterclass_id(), lid);

            if (nieuwDeelnemer.addDeelnemer()) {
                JOptionPane.showMessageDialog(null, "deelnemer toegevoegd");
                vulTabelDeelnemer(clsMasterclass.getMasterclass_id());
                vulTabelLeden();

            } else {
                System.out.println("masterclass toevoegen: opslaan: " + "error bij opslaan");
            }
        }
        }
    }//GEN-LAST:event_deelnemerToevoegenActionPerformed

    private void cancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelActionPerformed
        this.dispose();

    }//GEN-LAST:event_cancelActionPerformed

    private void tblDeelnemerMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblDeelnemerMouseClicked
        // TODO add your handling code here:
//        int row = tblDeelnemer.getSelectedRow();
//        String deelnemer = (String) tblDeelnemer.getModel().getValueAt(row, 0);
//        String email = (String) tblDeelnemer.getModel().getValueAt(row, 1);
//        new DeelnemersWijzigen(Integer.parseInt(deelnemer), email, clsMasterclass.getMasterclass_id()).setVisible(true);
//        this.setVisible(false);
    }//GEN-LAST:event_tblDeelnemerMouseClicked

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
//        // TODO add your handling code here:
       Masterclass voltooiMasterclass = new Masterclass(masterclass.getText());
        voltooiMasterclass.setStatus("voltooid");
        voltooiMasterclass.bijwerken();
        JOptionPane.showMessageDialog(null, "masterclass is voltooid");
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        // TODO add your handling code here:
        Masterclass updateMasterclass = new Masterclass(masterclass.getText());
        updateMasterclass.setStatus("inactief");
        updateMasterclass.bijwerken();
        JOptionPane.showMessageDialog(null, "masterclass is opgezegd");
    }//GEN-LAST:event_jButton3ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
                int row = tblDeelnemer.getSelectedRow();
        String deelnemer = (String) tblDeelnemer.getModel().getValueAt(row, 0);
        String email = (String) tblDeelnemer.getModel().getValueAt(row, 1);
        new DeelnemersWijzigen(Integer.parseInt(deelnemer), email, clsMasterclass.getMasterclass_id()).setVisible(true);
      //  this.setVisible(false);
    }//GEN-LAST:event_jButton2ActionPerformed

    private void btnVernieuwenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnVernieuwenActionPerformed
        this.vulTabelDeelnemer(clsMasterclass.getMasterclass_id());
        this.vulTabelLeden();
    }//GEN-LAST:event_btnVernieuwenActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(MasterclassBeheren.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(MasterclassBeheren.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(MasterclassBeheren.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(MasterclassBeheren.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new MasterclassBeheren().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField Datum;
    private javax.swing.JTextField Deelnemers;
    private javax.swing.JTextField Master;
    private javax.swing.JTextField Mstatus;
    private javax.swing.JTextField Tijd;
    private javax.swing.JButton btnVernieuwen;
    private javax.swing.JButton cancel;
    private javax.swing.JButton deelnemerToevoegen;
    private javax.swing.JTextField huisnr;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTextField masterclass;
    private javax.swing.JTextField postcode;
    private javax.swing.JTable tblDeelnemer;
    private javax.swing.JTable tblLeden;
    // End of variables declaration//GEN-END:variables
}
